﻿@using XRM.Security.WebUI.Consts
<div>
    @Html.Partial("_FileUploaderPartial", new ViewDataDictionary { {ViewDataConsts.UploadUrl, Url.Action("Upload", "CertRegister", ViewData[ViewDataConsts.UrlParameters])}, { ViewDataConsts.MaxUploadFiles, 1}, {ViewDataConsts.Accept, ".cer, .p7b"} })
    <p id="certUploadErrorMessage" class="error-message"></p>
    <div class="actions-centered">
        <button id="certUploadBtn" class="btn btn-primary" type="button" disabled="disabled">Загрузить сертификат</button>                        
    </div>
    <input id="dataId" type="hidden" name="dataId"/>
</div>

<script type="text/javascript">
    $("#upload_result").change(function () {
        var result = $.parseJSON($(this).val());
        if (!result.isSuccess) {
            $("#certUploadErrorMessage").html(result.error);
            $("#certUploadBtn").attr("disabled", "disabled");
        }
        else {
            $("#dataId").val(result.dataId);
            $("#certUploadErrorMessage").empty();
            $("#certUploadBtn").removeAttr("disabled");
        }
    });
    $("#certUploadBtn").click(function () {
        @if (ViewData.ContainsKey(ViewDataConsts.Callback))
            {
                <text>@(ViewData[ViewDataConsts.Callback])();</text>
            }
    });
</script>